﻿using Microsoft.Xna.Framework;


namespace LoD.WPClientLibrary.Animations {
    public class Throb : Animation {
        private bool _started;

        public Throb(float startScale, float endScale, float speed) {
            this._started = false;
            Animating = true;
            this.StartScale = startScale;
            this.EndScale = endScale;
            this.Speed = speed;
        }

        public float EndScale { get; set; }

        public float Speed { get; set; }
        public float StartScale { get; set; }

        public override Vector2 ModifyScale(Vector2 original) {
            if (!Animating) return original;

            Vector2 modified = original;

            if (!this._started) {
                modified.X = this.StartScale;
                modified.Y = this.StartScale;
                this._started = true;
            }

            modified.X += this.Speed;
            modified.Y += this.Speed;

            if (modified.X >= this.EndScale) this.Speed *= -1;
            else if (modified.X <= this.StartScale) Animating = false;

            return modified;
        }
    }
}